<include file="Public/min-header"/>
<style>
    ul.group-list {
        width: 96%;min-width: 1000px; margin: auto 5px;list-style: disc outside none;
    }
    ul.group-list li {
        white-space: nowrap;float: left;
        width: 150px; height: 25px;
        padding: 3px 5px;list-style-type: none;
        list-style-position: outside;border: 0px;margin: 0px;
    }
</style>
<script type="text/javascript">
    window.UEDITOR_Admin_URL = "__ROOT__/Public/plugins/Ueditor/";
    var URL_upload = "{$URL_upload}";
    var URL_fileUp = "{$URL_fileUp}";
    var URL_scrawlUp = "{$URL_scrawlUp}";
    var URL_getRemoteImage = "{$URL_getRemoteImage}";
    var URL_imageManager = "{$URL_imageManager}";
    var URL_imageUp = "{$URL_imageUp}";
    var URL_getMovie = "{$URL_getMovie}";
    var URL_home = "{$URL_home}";</script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/ueditor.all.min.js"></script>
<script type="text/javascript" charset="utf-8" src="__ROOT__/Public/plugins/Ueditor/lang/zh-cn/zh-cn.js"></script>
<script type="text/javascript">
    var editor;
    $(function () {
        //具体参数配置在  editor_config.js  中
        var options = {
            zIndex: 999,
            initialFrameWidth: "95%", //初化宽度
            initialFrameHeight: 400, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999,
            removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign', //允许的最大字符数 'fullscreen',
            pasteplain: false, //是否默认为纯文本粘贴。false为不使用纯文本粘贴，true为使用纯文本粘贴
            autoHeightEnabled: true,
            toolbars: [
                ['fullscreen', 'source', '|', 'undo', 'redo',
                    '|', 'bold', 'italic', 'underline', 'fontborder',
                    'strikethrough', 'superscript', 'subscript',
                    'removeformat', 'formatmatch', 'autotypeset',
                    'blockquote', 'pasteplain', '|', 'forecolor',
                    'backcolor', 'insertorderedlist',
                    'insertunorderedlist', 'selectall', 'cleardoc', '|',
                    'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                    'customstyle', 'paragraph', 'fontfamily', 'fontsize',
                    '|', 'directionalityltr', 'directionalityrtl',
                    'indent', '|', 'justifyleft', 'justifycenter',
                    'justifyright', 'justifyjustify', '|', 'touppercase',
                    'tolowercase', '|', 'link', 'unlink', 'anchor', '|',
                    'imagenone', 'imageleft', 'imageright', 'imagecenter',
                    '|', 'insertimage', 'emotion', 'insertvideo',
                    'attachment', 'map', 'gmap', 'insertframe',
                    'insertcode', 'webapp', 'pagebreak', 'template',
                    'background', '|', 'horizontal', 'date', 'time',
                    'spechars', 'wordimage', '|',
                    'inserttable', 'deletetable',
                    'insertparagraphbeforetable', 'insertrow', 'deleterow',
                    'insertcol', 'deletecol', 'mergecells', 'mergeright',
                    'mergedown', 'splittocells', 'splittorows',
                    'splittocols', '|', 'print', 'preview', 'searchreplace'
                ]
            ]
        };
        editor = new UE.ui.Editor(options);
        //editor.render("resume"); //  指定 textarea 的  id 为 goods_content
    });</script>
<div class="wrapper">
    <include file="Public/breadcrumb" />
    <section class="content">
        <div class="container-fluid">
            <div class="pull-right">
                <a href="javascript:history.go(-1)" data-toggle="tooltip" title="" class="btn btn-default" data-original-title="返回"><i class="fa fa-reply"></i></a>
            </div>
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="fa fa-list"></i>商品详情</h3>
                </div>
                <div class="panel-body">
                    <ul class="nav nav-tabs">
                        <li class="active"><a href="#tab_tongyong" data-toggle="tab">通用信息</a></li>
						<li><a href="#tab_goods_img" data-toggle="tab">商品相册</a></li>
                    </ul>
                    <form method="post" id="addEditGoodsForm" action="{:U('Admin/Goods/addEditGoodsForm')}" enctype="multipart/form-data">
                        <div class="tab-content">
                            <div class="tab-pane active" id="tab_tongyong">
                                <table class="table table-bordered">
                                    <tbody>
                                        <tr>
                                            <td width="15%" class = "text-right">商品名称:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.title}" name="title" class="form-control" style="width:550px;" />
                                                <span id="err_goods_name" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
										 <tr>
                                            <td class = "text-right">语言:</td>
                                            <td>
                                                <div class="col-xs-3" style = "width:250px">
                                                    <select name="lang" id="cat_id" class="form-control" style="width:250px;margin-left:-15px;">
                                                        <option value="cn" <if condition="'cn' eq $goodsInfo['lang']">selected="selected"</if>>中文</option>
														<option value="jn" <if condition="'en' eq $goodsInfo['lang']">selected="selected"</if>>日文</option>
                                                    </select>
                                                </div>
                                                <span id="err_cat_id" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">商品分类:</td>
                                            <td>
                                                <div class="col-xs-3" style = "width:250px">
                                                    <select name="cat_id" id="cat_id" class="form-control" style="width:250px;margin-left:-15px;">
                                                        <option value="0">请选择商品分类</option>
                                                        <foreach name="cat_list" item="v" key="k">
                                                            <option value="{$v['id']}" <if condition="$v['id'] eq $goodsInfo['cat_id']">selected="selected"</if> > {$v['name']}
                                                            </option>
                                                        </foreach>
                                                    </select>
                                                </div>
                                                <span id="err_cat_id" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">售价:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.price}" name="price" class="form-control" style="width:150px;" />
                                                <span id="err_shop_price" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
										<tr>
                                            <td class = "text-right">库存:</td>
                                            <td>
                                                <input type="text" value="{$goodsInfo.inventory}" name="inventory" class="form-control" style="width:150px;" />
                                                <span id="inventory" style="color:#F00; display:none;"></span>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td class = "text-right">上传商品图片:</td>
                                            <td>
												<input type="text" name="thumb" id="fileImage" value="{$goodsInfo.thumb}" class="form-control" style="width:300px;">
												<button type="button" class="layui-btn" id="upload_img">
												  <i class="layui-icon">&#xe67c;</i>上传图片
												</button>
                                                <if condition="$goodsInfo.thumb neq ''">
                                                    <img src="__ROOT__{$goodsInfo.thumb}" height="35">
                                                </if>
                                            </td>
                                    </tr>
                                    <tr>
                                        <td class = "text-right">是否显示:</td>
                                        <td>
                                            <label><input type="radio" name="status" value="1" <if condition="$goodsInfo['status'] eq 1">checked</if>> 显示 </label>
                                            <label style="margin-left:30px;"><input type="radio" name="status" value="0" <if condition="$goodsInfo['status'] eq 0">checked</if>> 不显示</label>
                                        </td>
                                    </tr>
									<tr>
										<td class = "text-right">要求备注:</td>
										<td>
											<textarea id="resume" name="resume" class="form-control" style="height:150px;">{$goodsInfo.resume}</textarea>
											<span id="err_goods_remark" style="color:#F00; display:none;"></span>
										</td>
									</tr>
                                    </tbody>
                                </table>
                            </div>
							<div class="tab-pane" id="tab_goods_img">
								<table class="table table-bordered">
									<tbody>
										<tr>
											<td>
											<div id="allimg">
											<foreach name="goodsImg" item="vo" key="k">
												<div style="width:100px; text-align:center; margin: 5px; display:inline-block;" class="goods_xc">
													<input type="hidden" value="{$vo['thumb']}" name="goods_img[]">
													<a onclick="" href="{$vo['thumb']}" target="_blank"><img width="100" height="100" src="{$vo['thumb']}"></a>
													<br>
													<a href="javascript:;" onclick="ClearPicArr2(this, '{$vo['thumb']}')">删除</a>
												</div>
											</foreach>
											</div>
											<button type="button" class="layui-btn" id="fileAllUpload">
											  <i class="layui-icon">&#xe67c;</i>上传图片
											</button>
	<!--
									<div class="goods_xc" style="width:100px; text-align:center; margin: 5px; display:inline-block;">
										<input type="hidden" name="goods_img[]" value="" />
										<a href="javascript:;" onclick="GetUploadify(10, '', 'goods', 'call_back2');"><img src="/Public/images/add-button.jpg" width="100" height="100" /></a>
										<br/>
										<a href="javascript:;">&nbsp;&nbsp;</a>
									</div> -->
										</td>
									</tr>
									</tbody>
								</table>
							</div>
                        </div>
						
                        <div class="pull-right">
                            <input type="hidden" name="act" value="{$act}">
                            <input type="hidden" name="id" value="{$goodsInfo.id}">
                            <input type="submit" class="btn btn-primary" value="保存">
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </section>
</div>
</body>
<script>
	$(function(){
		layui.use('upload', function(){
		  var upload = layui.upload;
		  //执行实例
		  //多图片上传
		  var goods_id = '{$goodsInfo.goods_id}';
		  upload.render({
			elem: '#fileAllUpload'
			,url: '/Admin/{$cont_name}/imageOne/'
			,multiple: true
			,done: function(res){
				var html = '';
				html+= '<div style="width:100px; text-align:center; margin: 5px; display:inline-block;" class="goods_xc">';
				html+= '	<input type="hidden" value="'+res.data.urlpath+'" name="goods_img[]">';
				html+= '	<a onclick="" href="'+res.data.urlpath+'" target="_blank"><img width="100" height="100" src="'+res.data.urlpath+'"></a>';
				html+= '	<br>';
				html+= '	<a href="javascript:;" onclick="ClearPicArr2(this,\''+res.data.urlpath+'\')">删除</a>';
				html+= '</div>';
				$('#allimg').append(html);
				if(goods_id){
					$.post('/Admin/Goods/addImg',{goods_id:goods_id,img:res.data.urlpath},function(){},'json');	
				}				
			}
		  });
		});
	})
    function add_spec(){
        var html='<tr>';
        html+='<td width="80" style="padding-top:30px;">规格名称:</td>';
        html+='<td width="150" style="padding-top:30px;">';
        html+='        <input name="spec_name[]" type="text" class="form-control"><input type="hidden" name="spec_id[]" value="0">';
        html+='</td>';
        html+='<td width="120" style="padding-left:40px;padding-top:30px;">规格价格:</td>';
        html+='<td width="150" style="padding-top:30px;">';
        html+='    <input name="spec_price[]" type="text" class="form-control">';
        html+='</td>';
        html+='<td width="120" style="padding-left:40px;padding-top:30px;">规格原价:</td>';
        html+='<td width="150" style="padding-top:30px;">';
        html+='    <input name="spec_mk_price[]" type="text" class="form-control">';
        html+='</td>';
        html+='</tr>';
        $('#spec_list').append(html);
    }
    // 上传商品相册回调函数
    function call_back2(paths) {
        var last_div = $(".goods_xc:last").prop("outerHTML");
        for (i = 0; i < paths.length; i++) {
            $(".goods_xc:eq(0)").before(last_div); // 插入一个 新图片
            $(".goods_xc:eq(0)").find('a:eq(0)').attr('href', paths[i]).attr('onclick', '').attr('target', "_blank"); // 修改他的链接地址
            $(".goods_xc:eq(0)").find('img').attr('src', paths[i]); // 修改他的图片路径
            $(".goods_xc:eq(0)").find('a:eq(1)').attr('onclick', "ClearPicArr2(this,'" + paths[i] + "')").text('删除');
            $(".goods_xc:eq(0)").find('input').val(paths[i]); // 设置隐藏域 要提交的值
        }
    }
    function ClearPicArr2(obj, path) {
        layer.confirm('确定要删除吗？', {
		  btn: ['确定','取消'] //按钮
		}, function(){
			 $.ajax({
				type: 'GET',
				url: "{:U('Admin/Uploadify/delupload')}",
				data: {
					action: "del",
					filename: path
				},
				success: function () {
					$(obj).parent().remove(); // 删除完服务器的, 再删除 html上的图片               
				}
			 });
			 $.ajax({
				type: 'GET',
				url: "{:U('Admin/Goods/delGoodsImg')}",
				data: {
					filename: path
				},
				success: function () {
					//
				}
			});
			layer.closeAll();
		}, function(){
		  	layer.closeAll();
		});        
    }
</script>
</html>
